home *** CD-ROM | disk | FTP | other *** search
Wrap
#include "RealWoofItem.h" #include <string.h> #include <Icons.h> #include "Draft.xh" #include "MemMgr.h" #include "Part.xh" #include "StorageU.xh" #include "CyberdogDef.h" #include "Debug.h" #include "WoofStream.xh" #include "ODFoci.h" #include "WoofURL.h" #include "WoofLibraryInit.h" #define INHERITED TRealCyberItem TRealWoofItem::TRealWoofItem() { fURL = nil; } TRealWoofItem::~TRealWoofItem() { if (fURL) { MMFree(fURL); fURL = nil; } } void TRealWoofItem::SetUpFromURL(Environment *ev, char* url, StringPtr defaultName) { unsigned short size; unsigned short hostNameLen; unsigned short procNameLen; char* hostName; char* procName; Str255 newName; ASSERT(fDefaultName == nil); ASSERT(fURL == nil); if (defaultName) { this->SetDefaultName(ev, defaultName); } else { // The host name is located just past the "doggie://" // We want the name of the item to be the process name // there is no host, or "proc On host" if there is a host. ParseWoofURL(url, &hostName, &hostNameLen, &procName, &procNameLen); newName[0] = 0; ASSERT(procNameLen > 0); // We need to make sure we don't overwrite a Str255!! if (procNameLen > 0) { BlockMove(procName, newName + 1, procNameLen); newName[0] = procNameLen; } if (hostNameLen > 0) { BlockMove(" On ", newName + procNameLen, 4); BlockMove(hostName, newName + procNameLen + 4, hostNameLen); newName[0] += (4 + hostNameLen); } this->SetDefaultName(ev, (StringPtr) newName); } size = strlen(url) + 1; fURL = (char *)MMAllocate(size); //•Err ASSERT(fURL != nil); BlockMove(url, fURL, size); } void TRealWoofItem::ExternalizeContent(Environment *ev, ODStorageUnit* su) { const ODValueType kODAppleTEXT = "Apple:OSType:Scrap:TEXT"; // •!• remove this when bug #1151636 has been resolved and kODAppleText (or whatever) has been redefined and works // // Add first value, which is of the kind of the CyberViewer, and has the // CyberItem as it's value. su->AddValue(ev, kTextViewerKind); this->StreamToStorageUnit(ev, su); // // Add second value, which is of kind "CyberItem", and has the // CyberItem as it's value. (this is identical to the above value) su->AddValue(ev, kCyberItemKind); this->StreamToStorageUnit(ev, su); // // Add third value, which is of the kind of scrapbook text, and has the // URL as it's value. su->AddValue(ev, kODAppleTEXT); StorageUnitSetValue(su, ev, strlen(fURL), (ODPtr) fURL); // su->SetValue(ev, strlen(fURL), (ODValue)fURL); } void TRealWoofItem::StreamToStorageUnit(Environment *ev, ODStorageUnit* su) { long length; ASSERT(fDefaultName); ASSERT(fURL); // CI ClassID Length length = strlen(kWoofItemClassName) + 1; StorageUnitSetValue(su, ev, sizeof(long), (ODPtr)& length); // su->SetValue(ev, sizeof(long), (ODValue)&length); // CI ClassID StorageUnitSetValue(su, ev, length, (ODPtr)(kWoofItemClassName)); // su->SetValue(ev, length, (ODValue)(kWoofItemClassName)); // Default Name Length length = fDefaultName[0] + 1; StorageUnitSetValue(su, ev, sizeof(long), (ODPtr)&length); // su->SetValue(ev, sizeof(long), (ODValue)&length); // Default Name StorageUnitSetValue(su, ev, length, (ODPtr)fDefaultName); // su->SetValue(ev, length, fDefaultName); // URL Length length = strlen(fURL) + 1; StorageUnitSetValue(su, ev, sizeof(long), (ODPtr)&length); // su->SetValue(ev, sizeof(long), (ODValue)&length); // URL StorageUnitSetValue(su, ev, length, (ODPtr)fURL); // su->SetValue(ev, length, fURL); } void TRealWoofItem::StreamFromStorageUnit(Environment *ev, ODStorageUnit* su) { long length; if (fDefaultName) { MMFree((Ptr)fDefaultName); ASSERT(!MemError()); fDefaultName = nil; } if (fURL) { MMFree((Ptr)fURL); ASSERT(!MemError()); fURL = nil; } // Default Name Length StorageUnitGetValue(su, ev, sizeof(long), (ODPtr) &length); // (void) su->GetValue(ev, sizeof(long), &length); fDefaultName = (StringPtr)MMAllocate(length); // •Err ASSERT(fDefaultName != nil); // Default Name StorageUnitGetValue(su, ev, length, (ODPtr) fDefaultName); // (void) su->GetValue(ev, length, fDefaultName); // URL Length StorageUnitGetValue(su, ev, sizeof(long), (ODPtr) &length); // (void) su->GetValue(ev, sizeof(long), &length); fURL = (char *)MMAllocate(length); //•Err ASSERT(fURL != nil); // URL StorageUnitGetValue(su, ev, length, (ODPtr) fURL); // (void) su->GetValue(ev, length, fURL); } TRealCyberItem* TRealWoofItem::Clone(Environment *ev) { TRealWoofItem* clone = new TRealWoofItem; //•Err clone->SetUpFromURL(ev, fURL, fDefaultName); return clone; } CICompareType TRealWoofItem::Compare(Environment *ev, TRealCyberItem* compare) { short strcmpResult; CICompareType result; strcmpResult = strcmp(fURL, ((TRealWoofItem*)compare)->fURL); if (strcmpResult < 0) { result = kCICompareLessThan; } else if (strcmpResult > 0) { result = kCICompareGreaterThan; } else { result = kCICompareEqual; } return result; } char* TRealWoofItem::GetURL(Environment *ev) { return fURL; } Handle TRealWoofItem::GetIconSuite(Environment *ev) { OSErr err; Handle suite; CResourceFocus rf(WoofLibraryGetResFileData()); err = ::GetIconSuite(&suite, kFirstWoofServiceShort, svAllAvailableData); if (err != noErr) { suite = nil; } return suite; } CyberStream* TRealWoofItem::CreateCyberStream(Environment *ev) { AppleCyberdog_WoofStream* stream; TRealWoofStream* realWoofStream; stream = new AppleCyberdog_WoofStream; // •Err ASSERT(stream != nil); realWoofStream = stream->GetWoofStream(ev); ASSERT(realWoofStream != nil); realWoofStream->Initialize(fURL); return stream; } ODTypeToken TRealWoofItem::GetContentKind(Environment *ev, ODSession* session) { return session->Tokenize(ev, kTextViewerKind); //•Err, outofmem exception }